<?php
/**
 * MemberModel.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/6/10
 * Time: 10:52
 */
namespace app\api\model;

use app\common\Singleton;
use think\Db;

class MemberModel
{
    use Singleton;

    public function save($flag,$data,$extend=[])
    {
        if(empty($flag))
        {
            // 添加
            $data['create_ts'] = time();
            return Db::name('member')
                ->insertGetId($data);
        }
        else
        {
            // 编辑
            $data['update_ts'] = time();
            return Db::name('member')
                ->where('id',$flag)
                ->update($data);
        }
    }

    public function get($where,$extend=[])
    {
        $handler = Db::name('member');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        return $handler
            ->where($where)
            ->find();
    }
}